package br.edu.ufcg.greengrid.event;

public class MachineAvailabilityEvent extends Event implements Comparable<MachineAvailabilityEvent>, Cloneable {

	private String id;

	private long timestamp;

	private long idletime;

	public MachineAvailabilityEvent(String id, long timestamp, long idletime) {
		super();
		this.id = id;
		this.timestamp = timestamp;
		this.idletime = idletime;
	}

	public String getId() {
		return id;
	}

	public long getTimestamp() {
		return timestamp;
	}
	
	public void incTimestamp(long value) {
		this.timestamp += value;
	}

	public long getIdletime() {
		return idletime;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + (int) (idletime ^ (idletime >>> 32));
		result = prime * result + (int) (timestamp ^ (timestamp >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		MachineAvailabilityEvent other = (MachineAvailabilityEvent) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (idletime != other.idletime)
			return false;
		if (timestamp != other.timestamp)
			return false;
		return true;
	}

	@Override
	public int compareTo(MachineAvailabilityEvent o) {
		if(this.timestamp != o.timestamp){
			return this.timestamp - o.timestamp > 0 ? 1 : -1;
		}
		
		if(this.timestamp != o.timestamp){
			return this.timestamp - o.timestamp > 0 ? 1 : -1;
		}
		
		return this.id.compareTo(o.id);
	}

	@Override
	public String toString() {
		
		return "MachineAvailabilityEvent [id=" + id + ", idletime=" + idletime + ", timestamp=" + timestamp + "]";
	}

	@Override
	public MachineAvailabilityEvent clone() {

		return new MachineAvailabilityEvent(this.id, this.timestamp, this.idletime);
	}
	
}
